package neuroBot.gui;

import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import neuroBot.bot.party.Main;
import neuroBot.exploit.Util;
import pokerLogic2.Global;

public class BotStartOptionsFrame {
	public JFrame frame;

	public JPanel optionPan = new JPanel();

	public JPanel buttonPan = new JPanel();

	public JButton startButton = new JButton("Start");

	public CheckboxGroup anzTablesGrp = new CheckboxGroup();

	public CheckboxGroup isPerfCritGrp = new CheckboxGroup();

	public CheckboxGroup limitGrp = new CheckboxGroup();

	public CheckboxGroup pokerFrNrGrp = new CheckboxGroup();

	public Integer[] positions = new Integer[] { -1, 1, 2, 3, 4, 5, 6, 7, 8, 9,
			10 };

	public JComboBox position1 = new JComboBox(positions);

	public JComboBox position2 = new JComboBox(positions);

	public JComboBox position3 = new JComboBox(positions);

	public JComboBox position4 = new JComboBox(positions);

	public GridBagLayout gridLay = new GridBagLayout();

	public GridBagLayout gridLay1 = new GridBagLayout();

	public boolean started = false;

	public BotStartOptionsFrame() {
		ActionListener action_start = new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Global.bigBlind = Integer.parseInt(limitGrp
						.getSelectedCheckbox().getLabel());
				Main.anzTables = Integer.parseInt(anzTablesGrp
						.getSelectedCheckbox().getLabel());
				Global.isPerfCritical = isPerfCritGrp.getSelectedCheckbox()
						.getLabel().contentEquals("ja");
				Main.pokerFrameNr = Integer.parseInt(pokerFrNrGrp
						.getSelectedCheckbox().getLabel());
				Main.positions = new Integer[] {
						(Integer) position1.getSelectedItem(),
						(Integer) position2.getSelectedItem(),
						(Integer) position3.getSelectedItem(),
						(Integer) position4.getSelectedItem() };
				started = true;
				frame.setVisible(false);
			}
		};
		startButton.addActionListener(action_start);
		frame = new JFrame();
		frame.setPreferredSize(new Dimension(350, 200));
		frame.setLocation(490, 342);
		frame.setTitle("PokerBot Startup Options");
		frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		frame.setLayout(gridLay);
		optionPan.setLayout(gridLay1);
		buttonPan.add(startButton, new GridBagConstraints(0, 0, 1, 1, 1, 1,
				GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0), 0, 0));
		frame.add(buttonPan, new GridBagConstraints(0, 0, 1, 1, 0, 0,
				GridBagConstraints.NORTH, 0, new Insets(0, 0, 0, 0), 0, 0));
		optionPan.add(new JLabel("Anzahl Tische:"), new GridBagConstraints(0,
				0, 1, 1, 1, 1, GridBagConstraints.CENTER, 0, new Insets(0, 0,
						0, 0), 0, 0));
		optionPan.add(new Checkbox("2", anzTablesGrp, true),
				new GridBagConstraints(1, 0, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("4", anzTablesGrp, false),
				new GridBagConstraints(2, 0, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		JPanel positionPane = new JPanel();
		positionPane.setLayout(new GridBagLayout());
		positionPane.add(position1, new GridBagConstraints(0, 0, 1, 1, 1, 1,
				GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0), 0, 0));
		positionPane.add(position2, new GridBagConstraints(1, 0, 1, 1, 1, 1,
				GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0), 0, 0));
		positionPane.add(position3, new GridBagConstraints(2, 0, 1, 1, 1, 1,
				GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0), 0, 0));
		positionPane.add(position4, new GridBagConstraints(3, 0, 1, 1, 1, 1,
				GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0), 0, 0));
		optionPan.add(new JLabel("Positionen: "), new GridBagConstraints(0, 1,
				1, 1, 1, 1, GridBagConstraints.CENTER, 0,
				new Insets(0, 0, 0, 0), 0, 0));
		optionPan.add(positionPane, new GridBagConstraints(1, 1, 10, 1, 1, 1,
				GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0), 0, 0));
		optionPan.add(new JLabel("Limit:"), new GridBagConstraints(0, 2, 1, 1,
				1, 1, GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0), 0,
				0));
		optionPan.add(new Checkbox("5", limitGrp, false),
				new GridBagConstraints(1, 2, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("10", limitGrp, false),
				new GridBagConstraints(2, 2, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("15", limitGrp, false),
				new GridBagConstraints(3, 2, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("25", limitGrp, true),
				new GridBagConstraints(4, 2, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("50", limitGrp, false),
				new GridBagConstraints(5, 2, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new JLabel("Performance-Kritisch:"),
				new GridBagConstraints(0, 3, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("ja", isPerfCritGrp, true),
				new GridBagConstraints(1, 3, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("nein", isPerfCritGrp, false),
				new GridBagConstraints(2, 3, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new JLabel("Poker-Frame-Nr:"), new GridBagConstraints(0,
				4, 1, 1, 1, 1, GridBagConstraints.CENTER, 0, new Insets(0, 0,
						0, 0), 0, 0));
		optionPan.add(new Checkbox("2", pokerFrNrGrp, true),
				new GridBagConstraints(1, 4, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("3", pokerFrNrGrp, false),
				new GridBagConstraints(2, 4, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("4", pokerFrNrGrp, false),
				new GridBagConstraints(3, 4, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("5", pokerFrNrGrp, false),
				new GridBagConstraints(4, 4, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		optionPan.add(new Checkbox("6", pokerFrNrGrp, false),
				new GridBagConstraints(5, 4, 1, 1, 1, 1,
						GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0),
						0, 0));
		frame.add(optionPan, new GridBagConstraints(0, 1, 0, 0, 0, 0,
				GridBagConstraints.CENTER, 0, new Insets(0, 0, 0, 0), 0, 0));
		frame.pack();
		frame.setVisible(true);
		frame.setAlwaysOnTop(true);
	}

	public void setOptions() {
		while (!started)
			Util.sleep(500);
	}
}
